﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace drcoderz.com.clocks.chrono
{
    public class ChronometerWatch : Control
    {
        public ChronometerWatch()
        {
            this.DefaultStyleKey = typeof(ChronometerWatch);
        }

        private MiniClockHour miniClockHours;
        private MiniClockSecond miniClockSeconds;
        private MiniClockMinute miniClockMinutes;

        private RotateTransform minuteHand;
        private RotateTransform hourHand;
        private RotateTransform secondHand;

        public override void OnApplyTemplate()
        {
            miniClockHours = this.GetTemplateChild("miniClockHours") as MiniClockHour;
            miniClockSeconds = this.GetTemplateChild("miniClockSeconds") as MiniClockSecond;
            miniClockMinutes = this.GetTemplateChild("miniClockMinutes") as MiniClockMinute;

            minuteHand = this.GetTemplateChild("minuteHand") as RotateTransform;
            hourHand = this.GetTemplateChild("hourHand") as RotateTransform;
            secondHand = this.GetTemplateChild("secondHand") as RotateTransform;

            //apply some defaults
            miniClockHours.HandColor = miniClockSeconds.HandColor = miniClockMinutes.HandColor = HandColor;
            minuteHand.Angle = Minutes;
            hourHand.Angle = Hours;
            secondHand.Angle = Seconds;

            //miniClockHours.Value = MiniClockHourValue;
            //miniClockMinutes.Value = MiniClockMinuteValue;
            //miniClockSeconds.Value = MiniClockSecondValue;

            base.OnApplyTemplate();
        }

        #region Colors and Labels

        public Brush HandColor
        {
            get { return (Brush)GetValue(HandColorProperty); }
            set
            {
                SetValue(HandColorProperty, value);
                if (miniClockSeconds != null && miniClockHours != null && miniClockMinutes != null)
                {
                    miniClockHours.HandColor = miniClockSeconds.HandColor = miniClockMinutes.HandColor = value;
                }
            }
        }

        // Using a DependencyProperty as the backing store for HandColor.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty HandColorProperty =
            DependencyProperty.Register("HandColor", typeof(Brush), typeof(ChronometerWatch), new PropertyMetadata(new SolidColorBrush(Colors.Red)));


        public string TopLabel
        {
            get { return (string)GetValue(TopLabelProperty); }
            set { SetValue(TopLabelProperty, value); }
        }

        // Using a DependencyProperty as the backing store for TopLabel.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TopLabelProperty =
            DependencyProperty.Register("TopLabel", typeof(string), typeof(ChronometerWatch), new PropertyMetadata("DRCODERZ"));



        public string BottomLabel
        {
            get { return (string)GetValue(BottomLabelProperty); }
            set { SetValue(BottomLabelProperty, value); }
        }

        // Using a DependencyProperty as the backing store for BottomLabel.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty BottomLabelProperty =
            DependencyProperty.Register("BottomLabel", typeof(string), typeof(ChronometerWatch), new PropertyMetadata("CHRONOMETER WATCH"));
        
        #endregion

        #region Hands
        // HANDS

        public int Hours
        {
            get { return (int)GetValue(HoursProperty); }
            set { 
                SetValue(HoursProperty, value);
                if (hourHand != null)
                    hourHand.Angle = value;
            }
        }

        // Using a DependencyProperty as the backing store for Hours.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty HoursProperty =
            DependencyProperty.Register("Hours", typeof(int), typeof(ChronometerWatch), new PropertyMetadata(null));


        public int Minutes
        {
            get { return (int)GetValue(MinutesProperty); }
            set { 
                SetValue(MinutesProperty, value);
                if (minuteHand != null)
                    minuteHand.Angle = value;
            }
        }

        // Using a DependencyProperty as the backing store for Minutes.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MinutesProperty =
            DependencyProperty.Register("Minutes", typeof(int), typeof(ChronometerWatch), new PropertyMetadata(null));


        public int Seconds
        {
            get { return (int)GetValue(SecondsProperty); }
            set { 
                SetValue(SecondsProperty, value);
                if (secondHand != null)
                    secondHand.Angle = value;
            }
        }

        // Using a DependencyProperty as the backing store for Seconds.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty SecondsProperty =
            DependencyProperty.Register("Seconds", typeof(int), typeof(ChronometerWatch), new PropertyMetadata(null));

        
        #endregion

        #region MiniClockValues



        public int MiniClockHourValue
        {
            get { return (int)GetValue(MiniClockHourValueProperty); }
            set { SetValue(MiniClockHourValueProperty, value);
            if (miniClockHours != null)
                miniClockHours.Value = value;
            }
        }

        // Using a DependencyProperty as the backing store for MiniClockHourValue.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MiniClockHourValueProperty =
            DependencyProperty.Register("MiniClockHourValue", typeof(int), typeof(ChronometerWatch), new PropertyMetadata(null));



        public int MiniClockMinuteValue
        {
            get { return (int)GetValue(MiniClockMinuteValueProperty); }
            set { SetValue(MiniClockMinuteValueProperty, value);
                if (miniClockMinutes != null)
                miniClockMinutes.Value = value;
            }
        }

        // Using a DependencyProperty as the backing store for MiniClockMinuteValue.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MiniClockMinuteValueProperty =
            DependencyProperty.Register("MiniClockMinuteValue", typeof(int), typeof(ChronometerWatch), new PropertyMetadata(null));




        public int MiniClockSecondValue
        {
            get { return (int)GetValue(MiniClockSecondValueProperty); }
            set { SetValue(MiniClockSecondValueProperty, value);
            if (miniClockSeconds != null)
                    miniClockSeconds.Value = value;
            }
        }

        // Using a DependencyProperty as the backing store for MiniClockSecondValue.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MiniClockSecondValueProperty =
            DependencyProperty.Register("MiniClockSecondValue", typeof(int), typeof(ChronometerWatch), new PropertyMetadata(null));

        

        #endregion

    }
}
